package com.struts2.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.struts2.model.Product_line;
import com.struts2.service.ProductListService;
import com.struts2.service.ProductSearchService;


public class ProductSearchAction extends ActionSupport implements ModelDriven<List<Product_line>>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	 

	/*
	private String a;
	private String b;
	*/
	
	
	private String gender;
	private String type;
	private String category;
	
	private int lower;
	private int upper;
	
	
	public int getUpper() {
		return upper;
	}

	public void setUpper(int upper) {
		this.upper = upper;
	}

	public int getLower()
	{
		return lower;
	}
	
	public void setLower(int price)
	{
		this.lower = price;
	}

	
	public String getGender() {
		return gender;
	}


	public void setGender(String gender) {
		this.gender = gender;
	}


	public String getCategory() {
		return category;
	}


	public void setCategory(String category) {
		this.category = category;
	}


	public String getType() {
		return type;
	}


	public void setType(String type) {
		this.type = type;
	}


	private List<String> leftSideMenuList;
	
	private List<String> leftSideSubMenuList;

	private int productPerPage = 10;
	private int pageNum =1;
	private int maxPage =0;
	public int getPageNum() {
		return pageNum;
	}


	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

//	private int offset = (pageNum - 1) * productPerPage;

	

	
	private List<Product_line> product_line;

	//***********************************************

	public List<Product_line> getProduct_line() {
		return product_line;
	}


	public void setProduct_line(List<Product_line> product_line) {
		this.product_line = product_line;
	}


	/////////////////////////////////////////////////

	public String execute() {
 
		ProductSearchService productListService = new ProductSearchService();
		product_line = productListService.GetProductList(product_line,productPerPage, pageNum, gender, type, category, lower, upper);
		
		
		double a = Math.ceil((double)productListService.GetProductCount(product_line, gender, type, category, lower, upper)/productPerPage);
		setMaxPage((int)a);
		
		leftSideMenuList = new ArrayList<String>();
	//	leftSideMenuList.add("menu1");
	//	leftSideMenuList.add("menu2");
	//	leftSideMenuList.add("menu3");
		leftSideMenuList = productListService.getLeftSideMenu(leftSideMenuList, gender, type, category);
		
		leftSideSubMenuList = new ArrayList<String>();

		if(category!="")
		{
			leftSideSubMenuList = productListService.getLeftSubSideMenu(leftSideSubMenuList, gender, type, category);
			// leftSideSubMenuList.add("menu3");
		}
		//System.out.println("size: " + users.size());
		System.out.println(product_line);
		System.out.println(gender + "  \n" + type +"  \n" + category);
		return SUCCESS;
	}



	@Override
	public List<Product_line> getModel() {
		// TODO Auto-generated method stub
		return product_line;
	}

	/***********************************************
	public String getB() {
		return b;
	}


	public void setB(String b) {
		this.b = b;
	}


	public String getA() {
		return a;
	}


	public void setA(String a) {
		this.a = a;
	}
	*/////////////////////////////////////////////////


	public int getMaxPage() {
		return maxPage;
	}


	public void setMaxPage(int maxPage) {
		this.maxPage = maxPage;
	}


	public List<String> getLeftSideMenuList() {
		return leftSideMenuList;
	}


	public void setLeftSideMenuList(List<String> leftSideMenuList) {
		this.leftSideMenuList = leftSideMenuList;
	}


	public List<String> getLeftSideSubMenuList() {
		return leftSideSubMenuList;
	}


	public void setLeftSideSubMenuList(List<String> leftSideSubMenuList) {
		this.leftSideSubMenuList = leftSideSubMenuList;
	}


	



	
	
}
